package com.sc.controller;

import com.sc.service.ClazzService;
import com.sc.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 用于统计分析数据的控制器
 * @author LiYe
 */
@Tag(name="StatisticsController", description = "统计分析接口控制器")
@RestController
@RequestMapping("/api/v1/stats")
public class StatisticsController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private ClazzService clazzService;

//    @Autowired
//    private EmpService empService;

    @Operation(summary = "统计总学生数、在陪学生数、在陪班级数、在执员工数")
    @GetMapping("total")
    public List<Map> total() {
        Map<String, Object> totalStudentNum = studentService.totalStudent();
        Map<String, Object> livingStudentNum = studentService.livingStudent();
        Map<String, Object> livingClazzNum = clazzService.livingClazz();
        List<Map> maps = new ArrayList<>();
        maps.add(totalStudentNum);
        maps.add(livingStudentNum);
        maps.add(livingClazzNum);
        return maps;
    }

    /**
     * 统计所有班级（最近一次课的）出勤率
     * @return
     */
    @Operation(summary = "统计所有班级（最近一次课的）出勤率")
    @GetMapping("allClassesAttendance")
    public Object allClassesAttendance() {
        List<Map> list = new LinkedList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("name", "JN24-1");
        map.put("value", 0.8);
        list.add(map);
        map = new HashMap<>();
        map.put("name", "JN24-2");
        map.put("value", 0.98);
        list.add(map);
        map = new HashMap<>();
        map.put("name", "JN24-3");
        map.put("value", 0.65);
        list.add(map);
        return list;
    }
    /**
     * 检索每个年级学生人数
     * @return
     */
    @Operation(summary = "统计每个年级学生人数")
    @GetMapping("stuNumInEachGrade")
    public Object stuNumInEachGrade() {
        List<Map> list = new LinkedList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("name", "2021");
        map.put("value", 100);
        list.add(map);
        map = new HashMap<>();
        map.put("name", "2022");
        map.put("value", 200);
        list.add(map);
        map = new HashMap<>();
        map.put("name", "2023");
        map.put("value", 147);
        list.add(map);
        return list;
    }
}
